package Chapter1.find;

public class SecondFind {
    public static void main(String[] args) {
        int nums[] = {1, 2, 3, 4, 5};
        System.out.println(find(nums, 41));
    }

    public static int find(int[] nums, int target) {
        int len = nums.length;
        int left = 0;
        int right = len - 1;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (target > nums[mid]) {
                left = mid + 1;
            } else if (target == nums[mid]) {
                return mid;
            } else if (target < nums[mid]) {
                right = mid - 1;
            }
        }
        return -1;
    }
}
